package com.zat.mes.andrmes.customerview.adapter

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.ParantTypeItem

/**
 *通用底部弹框
 */
class BottomDialogAdapter(layoutResId: Int) : BaseQuickAdapter<ParantTypeItem, BaseViewHolder>(
    layoutResId
) {
    var selectList: MutableList<ParantTypeItem> = ArrayList()


    override fun convert(helper: BaseViewHolder, item: ParantTypeItem) {
        helper.setText(R.id.tvNameItemDialog, item?.typename)
        val ivSelect = helper.getView<ImageView>(R.id.ivSelectItemDialog)
        if (selectList.contains(item)) {
            //去重
            ivSelect.setImageResource(R.mipmap.ico_selected)
        } else {
            ivSelect.setImageResource(R.mipmap.ico_unselect)
        }
        helper.itemView.setOnClickListener {
            if (selectList.contains(item)) {
                selectList.remove(item)
            } else {
                if (item != null) {
                    selectList.add(item)
                }
            }
            notifyDataSetChanged()
        }

    }
}